#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <iterator>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 10005;
int main()
{
	int a[20][11];
	int temp[16][11];
	memset(a, 0, sizeof(a));
	memset(temp, 0, sizeof(temp));

	for (int i = 1; i <= 15; i++)
	{
		for (int j = 1; j <= 10; j++)
		{

			cin >> a[i][j];

			temp[i][j] = a[i][j];
		}
	}
	int b[5][5];
	for (int i = 1; i <= 4; i++)
	{
		for (int j = 1; j <= 4; j++)
			cin >> b[i][j];
	}
	int x, y = 0;
	cin >> x;
	x--;
	int index = 0;
	for (int i = 4; i >= 1; i--)
	{
		for (int j = 1; j <= 4; j++)
			if (b[i][j])index = i;
		if (index)break;
	}
	while (1)
	{
		int flag = 0;
		if (y + index == 15)
		{

			break;
		}
		for (int i = 1; i <= 4; i++)
		{
			for (int j = 1; j <= 4; j++)
			{
				if (temp[i + y + 1][j + x] * b[i][j])
				{
					flag = 1;
					break;
				}
			}
			if (flag)break;
		}
		if (!flag)
		{
			for (int i = 1; i <= 4; i++)
			{
				for (int j = 1; j <= 4; j++)
				{
					if (!temp[i + y + 1][j + x])
						a[i + y + 1][j + x] = b[i][j];
				}
			}
			y++;
			for (int i = 1; i <= 10; i++)
			{
				a[y][i] = temp[y][i];
			}
		}
		else
		{
			break;

		}
	}
	for (int i = 1; i <= 15; i++)
	{
		for (int j = 1; j <= 10; j++)
		{
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}

	return 0;
}

/*
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0
1 1 1 0 0 0 1 1 1 1
0 0 0 0 1 0 0 0 0 0
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1
1 0 0 1
1 0 0 1
0 0 0 0

*/